package dang.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;

import dang.dao.OrderDao;
import dang.entity.Order;
import dang.entity.ReceiveAddress;
import dang.exception.DangException;

public class OrderDaoImpl  implements OrderDao {
	private Session s;
	@Autowired
	public void setS(Session s) {
		this.s = s;
	}
	
	@Override
	public void saveAddress(ReceiveAddress receiveAddress) throws DangException  {
		s.save(receiveAddress);
	}

	@Override
	public List<ReceiveAddress> findByUserId(int userId) throws DangException  {
		String hql="from ReceiveAddress r where r.user_id=?";
		List<ReceiveAddress> addresses=s.createQuery(hql).setParameter(0, userId).list();
		return addresses;
	}

	@Override
	public int saveOrder(Order order) throws DangException  {
		Integer orderId=(Integer) s.save(order);
		return orderId;
	}

}
